package com.pony.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.community.R;
import com.pony.listener.DeleteCourseListner;
import com.pony.model.MyCourseModel;

public class MyMeCourseListAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<MyCourseModel> list_result;
	private int posIndex;
	private Context mContext;
	private DeleteCourseListner mDeleteListner;

	public MyMeCourseListAdapter(Context context, List<MyCourseModel> list_result,DeleteCourseListner deleteListner) {
		mContext = context;
		inflater = LayoutInflater.from(context);
		this.list_result = list_result;
		this.mDeleteListner= deleteListner;
	}

	@Override
	public int getCount() {
		return list_result.size();
	}

	@Override
	public Object getItem(int position) {
		return list_result.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_mycourseleavemessage, null);
			holder = new ViewHolder();
			holder.courseName = (TextView) convertView.findViewById(R.id.courseName);
			holder.courseMsg = (TextView) convertView.findViewById(R.id.courseMsg);
			holder.mivDelete = (ImageView) convertView.findViewById(R.id.mivDelete);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		try {
			holder.courseName.setText(list_result.get(position).getMycourseName());
			holder.courseName.setTextColor(Color.parseColor("#ff0000"));
			holder.courseMsg.setText(list_result.get(position).getMycourseAddress() + "(" + list_result.get(position).getMycourseTime() + ")");
			holder.mivDelete.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					mDeleteListner.setDelete(position, list_result.get(position));
				}
			});
		} catch (Exception e) {
			// TODO: handle exception
		}

		return convertView;

	}

	private class ViewHolder {
		private TextView courseName;
		private TextView courseMsg;
		private ImageView mivDelete;
	}

	public void setPos(int pos) {
		posIndex = pos;
	}

}
